package delayMessage.cycle;


import delayMessage.queue.JobCallBack;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * 延迟环形队列
 *
 * Created by Zhou_Bing on 2018/9/29.
 */
public class DelayCycle {

    private Set<Job>[] cycle;
    private int length;

    DelayCycle(int length){
        cycle = new Set[length];
        this.length = length;
    }

    public int length(){
        return this.length;
    }

    public void add(int delaySecond,JobCallBack callBack){
        int index = delaySecond%length;
        if(cycle[index]==null){
            cycle[index] = new HashSet<>();
        }
        cycle[index].add(new Job(delaySecond,callBack));
    }

    public Set<Job> get(int index){
        return cycle[index];
    }
}
